package com.Object.EqualsExercise;

/**
 * @Author 小闽
 * @Date 2024/8/14 9:43
 * @PackageName: com.Object.EqualsExercise
 * @ClassName: Person
 * @Description: 人类
 * @Version 1.0
 */
public class Person {
    private String name;
    private int age;
    private char gender;

    /**
     * 构造器
     * @param name
     * @param age
     * @param gender
     */
    public Person(String name, int age, char gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }
    /**
     * 重写equals方法
     */
    public boolean equals(Object obj){
        // 判断当前对象和传入的对象是否为同一个对象
        if (this == obj){
            return true;
        }
        if (obj instanceof Person){
          Person p = (Person) obj;
          return this.name.equals(p.name) && this.age == p.age && this.gender == p.gender;
        }
        return false;
    }
}
